var A= parent.J;  //父级的窗口方法
Array.prototype.removeByValue = function(val) {
    for(var i=0; i<this.length; i++) {
        if(this[i] == val) {
            this.splice(i, 1);
            break;
        }
    }
}
$(function(){
    /*ifrname是否加载完成*/
    var checkboxArrid = [];
    $("input:checkbox").on("change",function(){
        var val =$(this).val();
        var id= $(this).attr("id")
        if($(this).attr("checked")=="checked"){
            if(id!="all")checkboxArrid.removeByValue(val);
            $(this).removeAttr("checked");
        }else{
            if(id!="all")checkboxArrid.push(val);
            $(this).attr("checked",true);
        }
    });
    $("#all").on("click",function(){
        var  checkbox= $("#datalist input:checkbox");
        if(this.checked){
            checkbox.attr("checked",true);
            checkbox.each(function () {
                checkboxArrid.push($(this).val());
            })
        }else{
            checkbox.removeAttr("checked");
            checkboxArrid = [];
        }
    });
    $(".alldelete").on("click",function () {
        var action =$(this).attr("action");
        if(checkboxArrid.length==0){
            A.Msg("至少得选择1条以上数据")
            return;
        }
        var data = {
            'idArr':checkboxArrid,
            'action':action
        }
        A.confirm("确定要批量删除信息吗?",function(){
            $.ajax({
                url: '/admin/baseDelete',
                type: 'POST',
                data: data,
                success: function (data) {
                    if (data.success) {
                        A.Msg(data.msg)
                        A.closeAll()
                        location.reload()
                    }else{
                        A.Msg(data.msg)
                    }
                }
            });
        })
    })
    parent.$("#loading").hide();
});